var nowIndex = 1;
var pageCount = $('.page').size();
var startY,endY,moveY;
var didMove = false;

$('.page').on('touchstart touchmove touchend',function(e){
//	console.log(e);
	switch(e.type){
		case 'touchstart':
			startY = e.originalEvent.touches[0].clientY;
//			console.log(startY);
			break;
		case 'touchmove':
			endY = e.originalEvent.touches[0].clientY;
			didMove = true;
//			console.log(startY);
			break;
		case 'touchend':
			if(!didMove)return;
			moveY = endY-startY;
			if(moveY<0){//进入下一页
				if(nowIndex == pageCount)return;
				nowIndex++;
				$(this).addClass('toTop').next().removeClass('hidden').addClass('nextTop');
				$(this).on('webkitAnimationEnd',function(){
					$(this).removeClass('toTop').addClass('hidden').next().removeClass('nextTop');
					$(this).off('webkitAnimationEnd')
				})
				
			}else{//上一页
				if(nowIndex == 1)return;
				nowIndex--;
				$(this).addClass('toBottom').prev().removeClass('hidden').addClass('prevBottom');
				$(this).on('webkitAnimationEnd',function(){
					$(this).removeClass('toBottom').addClass('hidden').prev().removeClass('prevBottom');
					$(this).off('webkitAnimationEnd')
				})
			}
			break;
	}
})
